<template>
	<view class="unitRegisterResult">
		<view class="unitRegisterResult-search ff-bg-fff">
			<u-search placeholder="按单位名称查询" @change="unitNameChange" :height="72" input-align="center"
				v-model="unitName" :show-action="false"></u-search>
			<view class="ff-font-13 ff-line-height-1-3 ff-margin-top-10" v-if="tipsType">
				社会信用代码{{ socialCode }}下包含{{ unitToal }}个单位，请核实您的单位是否已存在。</view>
		</view>
		<view class="unitRegisterResult-content">
			<view
				class="unitRegisterResult-content-noResult ff-line-height-1-3 ff-font-13 ff-text-center ff-padding-top-30"
				v-if="!tipsType">
				该单位未注册，请点击下方按钮进行注册
			</view>
			<view v-if="unitList.length > 0">
				<view class="unitRegisterResult-content-box ff-bg-fff ff-border-radius-10 ff-padding-15"
					v-for="item of unitList" :key="item.id">
					<view class="ff-font-16 ff-font-weight-600">{{ item.companyName }}</view>
					<view class="ff-font-13 ff-flex unitRegisterResult-content-box-address">
						<view>
							<image
								src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/unit-address.png"
								mode=""></image>
						</view>
						<view>{{ item.companyAddr }}</view>
					</view>
					<view class="ff-font-13 ff-flex ff-padding-bottom-10 unitRegisterResult-personnelInfo">
						<view>
							<image
								src="https://fire-system.oss-cn-beijing.aliyuncs.com/web/fire-technology/unit-personel.png"
								mode=""></image>
						</view>
						<view>
							管理员：
							<text class="ff-margin-right-10">{{ item.managerLink }}</text>
							{{ item.managerPhone }}
						</view>
						<view class="unitRegisterResult-personnelInfo-staffBut">
							<u-button type="primary" size="mini"
								@click="goStaffRegister(item.companyName)">作为员工加入</u-button>
						</view>
					</view>
				</view>
			</view>

			<view class="unitRegisterResult-regBut ff-flex-between ff-color-fff ff-opacity-8 ff-font-15">
				<view>没有我的单位➝</view>
				<view><u-button @click="socialCompanyClick" type="primary" shape="circle">去注册</u-button></view>
			</view>
		</view>
		<f-loading ref="loading" />
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		name: 'unitRegisterResult',
		data() {
			return {
				unitName: '', // 搜索的内容
				tipsType: false, // 提示语是否展示
				socialCode: '', // 社会信用代码
				unitList: [], // 社会单位列表
				unitToal: '', // 社会单位列表长度
				unitLists: [] // 社会单位列表(用与模糊查询)
			};
		},
		onLoad(e) {
			// console.log('前页面传过来的数据------', e);
			this.socialCode = e.code;
			this.getUnitList(this.socialCode); // 获取社会单位列表
		},
		methods: {
			// 社会单位模糊查询
			unitNameChange(e) {
				//console.log('搜索框内容-----', e);
				let dat = [];
				this.unitLists.filter(res => {
					if (res.companyName.indexOf(e) != -1) {
						dat.push(res);
					}
				});
				this.unitList = dat;
			},
			// 请求单位列表数据
			getUnitList(code) {
				this.$refs.loading.openLoading('加载中···'); // 打开loading动画
				this.$http
					.get({
						url: `/company/queryByCode/${code}`
					})
					.then(res => {
						// console.log('根据社会信用代码获取社会单位列表---', res.data);
						if (res.code == 200) {
							this.unitToal = res.data.length;
							this.unitList = res.data;
							this.unitLists = res.data; // 用语模糊查询
							if (this.unitList.length > 0) {
								this.tipsType = true;
							}
						} else {
							this.$showToast(res.data.msg);
						}
						this.$refs.loading.closeLoading(); // 关闭loading动画
					});
			},
			// 员工加入某个单位
			goStaffRegister(name) {
				this.$pageJump.navigateTo('/pages/loginRegister/register/socialUnit/staff/staffRegisterSearch?name=' +
					name);
			},
			// 跳转到单位注册页面
			socialCompanyClick() {
				this.$pageJump.navigateTo('/pages/loginRegister/register/socialUnit/unit/unitRegisterOne?socialCode=' +
					this.socialCode);
			}
		},
		onShareAppMessage() {
			return {
				title: '分享小程序给朋友',
				path: '/pages/homePage/Home'
			};
		}
	};
</script>

<style lang="scss" scoped>
	.unitRegisterResult {
		&-search {
			position: fixed;
			top: 0;
			left: 0;
			z-index: 2;
			width: 100%;
			padding: 53rpx 30rpx 30rpx;

			.ff-font-13 {
				color: #ee0a24;
			}
		}

		&-content {
			padding-bottom: 200rpx;
			margin-top: 260rpx;

			&-noResult {
				color: #b5bbc8;
			}

			&-box {
				margin: 20rpx 24rpx;

				.ff-font-16 {
					color: #0b0e11;
				}

				.ff-font-13 {
					color: #5c5f65;

					image {
						width: 24rpx;
						height: 24rpx;
						margin-right: 7rpx;
					}
				}

				&-address {
					margin: 22rpx 0 10rpx;
				}
			}
		}

		&-personnelInfo {
			position: relative;

			.unitRegisterResult-personnelInfo-staffBut {
				position: absolute;
				right: 0;
			}
		}

		&-regBut {
			align-items: center;
			width: 94%;
			margin: 0 3%;
			border-radius: 70rpx;
			box-sizing: border-box;
			position: fixed;
			z-index: 11;
			bottom: 3%;
			left: 0;
			background: #000000;
			padding: 30rpx 20rpx 30rpx 40rpx;

			/deep/.u-size-default {
				height: 62rpx;
				line-height: 62rpx;
			}
		}

		/deep/.u-size-mini {
			font-size: 24rpx !important;
			height: 58rpx !important;
			line-height: 58rpx !important;
		}
	}
</style>